#!/usr/bin/perl

use strict;
use warnings;
require 'forum_common.pl';

connect_to_database() or bad_deal();
my $user = get_current_user(get_sess_id());

record_this_hit();

print header($forum::http_header), forum_start(forum_cpanel($user));

my $id = param('id');
unless (defined $id)
{
	print forum_error('No post specified!');
	goto gameover;
}


my ($post);
unless ($post = get_post($id))
{
	print forum_error();
	goto gameover;
}
my $board_title = escapeHTML($post->{B_TITLE});
my $topic_title = escapeHTML($post->{T_TITLE});

print	'Board: ',
		span({-class=>'title'},
			a({-href=>"board.cgi?id=$post->{BOARD}"}, $board_title)), br(),
		'Topic: ',
		span({-class=>'title'},
			a({-href=>"topic.cgi?id=$post->{TOPIC}"}, $topic_title)), br(),
		br(),
		'Post:', br();

print '<div id="posts">';
my $data_left = 1; # true
	my $u_usernm = escapeHTML($post->{U_USERNM});
	my $dt_posted = timefmt($post->{DT_POSTED});
	my $div_content = div({-class=>'postc content'},as_post($post->{CONTENT}));
	my $edit = cant_editpost($user, $post) ? '' :
				div({-class=>'edit'},
					'('.a({-href=>"editpost.cgi?id=$post->{ID}"},'Edit').')');
	print	'<div class="post">',
			($data_left ? '' : $div_content),
			"<a id=\"post$post->{ID}\"></a>",
			div({-class=>'postc data'},
				div({-class=>'usernm'},
					a({-href=>"member.cgi?id=$post->{POSTER}"},
						$u_usernm)),
				div({-class=>'dt'}, $dt_posted),
				$edit),
			($data_left ? $div_content : ''),
			'</div>';
print '</div>';

gameover:
print forum_end();
forum_disconnect();
